home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / dev / c / SUPRALib.lha / SUPRALib / Developer / Source.ORG / MakePath.c < prev    next >
C/C++ Source or Header  |  1999-05-17  |  2KB  |  69 lines

  1. /****** MakePath *********************************************************
  2. *
  3. *   NAME
  4. *       MakePath -- Creates all new directories in a path (V10)
  5. *
  6. *   SYNOPSIS
  7. *       suc = MakePath(path)
  8. *
  9. *       BOOL = MakePath(char *);
  10. *
  11. *   FUNCTION
  12. *       This function creates a whole specified path of directories.
  13. *       It works similar to CreateDir() except that it can create
  14. *       more subdirs at once. User does not have to care if all
  15. *       sub dirs in a specified path already exist or not.
  16. *
  17. *   INPUTS
  18. *       path - pointer to a path string to create. A path can be
  19. *       relative to a current dir or absolute.
  20. *
  21. *   RESULT
  22. *       suc - TRUE if succeeds (path was created). FALSE if a path
  23. *       could not be created.
  24. *
  25. *   EXAMPLE
  26. *
  27. *       suc = MakePath("RAM:way/to/many/dirs");
  28. *
  29. *       The above function will try to make all non-existing dirs
  30. *       in a path RAM:way/to/many/dirs.
  31. *
  32. *   SEE ALSO
  33. *       CreateDir()
  34. *
  35. *********************************************************************/
  36.  
  37. #include<proto/dos.h>
  38. #include<dos/dos.h>
  39. #include<string.h>
  40.   
  41. BOOL MakePath(char *path)
  42. {
  43. char *p=path;
  44. BPTR lock;
  45. struct FileInfoBlock fib;
  46. BOOL err=FALSE;
  47.  
  48.     do {
  49.         p = strchr(p,'/');
  50.         if (p != NULL) p[0] = '\0';
  51.         if (lock = Lock(path, ACCESS_READ)) {
  52.             if (Examine(lock, &fib)) {
  53.                 if (fib.fib_DirEntryType < 0) err = TRUE;
  54.             } else err = TRUE;
  55.             UnLock(lock);
  56.             if (err) return(FALSE);
  57.         } else if (lock = CreateDir(path)) {
  58.             UnLock(lock);
  59.         } else return(FALSE);
  60.         if (p != NULL) {
  61.             p[0] = '/';
  62.             p++;
  63.         }
  64.     } while (p != NULL);
  65.  
  66.     return(TRUE);
  67. }
  68.  
  69.